package org.scmpatrol.scm.action;

import java.io.Serializable;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Lob;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.scmpatrol.scm.SCMPath;

@Entity
@DiscriminatorValue("A")
public class SCMAddAction extends SCMAction implements Serializable {

	private static final long serialVersionUID = 6476374651051182850L;

	boolean copied = false;
	String copiedFrom;
	String copiedFromRevision;
	
	/**
	 * Content for text modification (file or properties).<br>
	 * This field is not set if the addition is from another revision (copiedFrom is not null)
	 */
	@Lob
	private String content;

    public SCMAddAction() {
        super();
    }

	public SCMAddAction(SCMPath path) {
		super(path);
	}

	public String getCopiedFromRevision() {
		return copiedFromRevision;
	}

	public void setCopiedFromRevision(String copiedFromRevision) {
		if (StringUtils.isNotBlank(copiedFromRevision)) {
			copied = true;
			this.copiedFromRevision = copiedFromRevision;
		} else {
			copied = false;
		}
	}

	public boolean isCopied() {
		return copied;
	}

	public String getCopiedFrom() {
		return copiedFrom;
	}

	public void setCopiedFrom(String copiedFrom) {
		if (StringUtils.isNotBlank(copiedFrom)) {
			copied = true;
			this.copiedFrom = copiedFrom;
		} else {
			copied = false;
		}
	}

	@Override
	public SCMActionTypeEnum getActionType() {
		return SCMActionTypeEnum.ADD;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getContent() {
		return content;
	}

	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}

}
